

from math import inf


# 中间连续的数组和使用前缀和的形式

class Solution:

    def maxSubarray(self, nums: list):

        ans = -inf
        min_pre, pre = 0, 0

        for x in nums:
            pre += x

            ans = max(ans, pre - min_pre)

            min_pre = min(pre, min_pre)

        
        return ans


